from flask import request, jsonify, Blueprint
import urllib.parse
from db_config import db

from app import socketio


# chat = Blueprint('chat',__name__)

# SocketIO 支持确认回调，确认客户端收到了一条消息：
def ack():
    print('message was received!')
# @socketio.on('connect', namespace='/chat')
# def test_connect():
#     emit('my response', {'data': 'Connected'}, callback=ack)

@socketio.on('message')
def handle_message(message):
    message = urllib.parse.unquote(message)
    print(message)
    send(message,broadcast=True)

@socketio.on('connect', namespace='/chat')
def test_connect():
    print('-----connect-----')
    emit('my response', {'data': 'Connected'})

@socketio.on('disconnect', namespace='/chat')
def test_disconnect():
    print('-----disconnect-----')
    print('Client disconnected')




